﻿namespace LearnDSSortings;

public class ShellSort
{
    public void Sort(int[] arr)
    {
        int n = arr.Length;
        int gap = n / 2;
        while (gap > 0)
        {
            int i = gap;
            while (i < n)
            {
                int temp = arr[i];
                int j = i - gap;
                while (j >= 0 && arr[j] > temp)
                {
                    arr[j + gap] = arr[j];
                    j = j - gap;
                }

                arr[j + gap] = temp;
                i = i + 1;
            }

            gap = gap / 2;
        }
    }

    private void Swap(int[] arr, int i, int j)
    {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}